<?php

namespace app\advertiser\controller;

use app\advertiser\service\AdMatterService;
use app\BaseController;
use think\facade\Request;
use think\response\Json;

/**
 * 微信小程序推广物
 */
class AdMiniProgram extends BaseController
{
    /**
     * 小程序类型
     * @var int
     */
    private int $type = 2;

    /**
     * 微信小程序推广物列表
     * @param AdMatterService $adMatterService
     * @return Json
     */
    public function list(AdMatterService $adMatterService): Json
    {
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        $params['name'] = Request::param('name/s');
        $params['start_time'] = Request::param('start_time/d', 0);
        $params['end_time'] = Request::param('end_time/d', 0);
        return $adMatterService->list($params, $this->type);
    }

    /**
     * 微信小程序推广物全部列表
     * @param AdMatterService $adMatterService
     * @return Json
     */
    public function listAll(AdMatterService $adMatterService): Json
    {
        $params['name'] = Request::param('name/s');
        return $adMatterService->listAll($params, $this->type);
    }

    /**
     * 微信小程序推广物增加
     * @param AdMatterService $adMatterService
     * @return Json
     */
    public function add(AdMatterService $adMatterService): Json
    {
        $params['name'] = Request::param('name/s', '');
        $params['appid'] = Request::param('appid/s', '');
        $params['desc'] = Request::param('desc/s', '');
        $params['avatar'] = Request::param('avatar/s', '');
        $params['qrcode'] = Request::param('qrcode/s', '');
        return $adMatterService->add($params, $this->type);
    }

    /**
     * 微信小程序推广物编辑
     * @param AdMatterService $adMatterService
     * @return Json
     */
    public function edit(AdMatterService $adMatterService): Json
    {
        $params['id'] = Request::param('id/d');
        $params['name'] = Request::param('name/s', '');
        $params['desc'] = Request::param('desc/s', '');
        $params['avatar'] = Request::param('avatar/s', '');
        $params['qrcode'] = Request::param('qrcode/s', '');
        return $adMatterService->edit($params, $this->type);
    }

    /**
     * 微信小程序推广物删除
     * @param AdMatterService $adMatterService
     * @return Json
     */
    public function del(AdMatterService $adMatterService): Json
    {
        $id = Request::param('id/d', 0);
        return $adMatterService->del($id, $this->type);
    }

}